package com.web.controller;

import com.web.pojo.Person;
import com.web.service.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * @Description 个人信息操作
 * @Author zhu_jinsheng[zhu_js@suixingpay.com]
 * @Date 2019/12/3 21:46
 * @Version 1.0
 */
@Controller
@RequestMapping("/person")
public class PersonController {

    @Autowired
    private PersonService personService;

    @RequestMapping("/index_show")//不能和返回值相同，不然会报错
    @ResponseBody
    public String show1() {
        return "index";
    }

    /**
     * @Description 添加个人信息
     * @Author zhu_jinsheng[zhu_js@suixingpay.com]
     * @Param request:  http请求
     * @return: java.lang.String
     * @Date 2019/12/6 16:24
     */
    @RequestMapping("/add")
    public String insertPerson(HttpServletRequest request)
    {
        Person person = new Person();
        person.setId(Integer.parseInt(request.getParameter("id")));
        person.setName(request.getParameter("name"));
        personService.insertPerson(person);
        //重定向
        return "redirect:index.html";
//        解决Request method 'POST' not supported问题的4种方法
//        1、将login.html中表单提交方式改为GET
//        2、将 return “/login.html”; 改为 return “redirect:/login.html”;
//        3、将前端HTML改用JSP
//        4、security的配置文件中使用.defaultSuccessUrl("/index")
    }
}
